package io.gitee.zhangbinhub.acp.cloud.server.hello.controller;

import io.gitee.zhangbinhub.acp.boot.log.LogAdapter;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @since JDK 17
 */
@RestController
public class HelloController {

    private final LogAdapter logAdapter;

    @Autowired
    public HelloController(LogAdapter logAdapter) {
        this.logAdapter = logAdapter;
    }

    @GetMapping(value = "/hello", produces = MediaType.TEXT_PLAIN_VALUE)
    public ResponseEntity<Object> hello(HttpServletRequest request, @RequestParam("name") String name) {
        String respon = "hello response: name=" + name;
        logAdapter.info(respon);
        return ResponseEntity.ok(respon);
    }

}
